package com.cyt.web.controller.work.divideclass;

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.base.util.StringUtils;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.BaseController;
import com.cyt.work.divideclass.model.vo.DivideclassClassVo;
import com.cyt.work.divideclass.model.vo.DivideclassStudentVo;
import com.cyt.work.divideclass.service.DivideclassStudentService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 智能分班学生表,分班时导入的学生信息-智能分班学生控制层
 *
 * @author caideyong
 * @date 2019-12-20 14:24:32
 */
@RestController
public class DivideclassStudentController extends BaseController {

    @Resource
    private DivideclassStudentService divideclassStudentService;

    /**
     * 统一跳转
     *
     * @param applyId 应用id
     * @param classId 班级id
     * @return Model
     * @author caideyong
     * @date 2019-12-20 14:24:32
     */
    @RequestMapping("/divideclass/divideclassstudent/{pageName}")
    public ModelAndView goPage(@PathVariable("pageName") String pageName, String applyId, String classId) {
        ModelAndView view = new ModelAndView("/work/divideclass/divideclassstudent/" + pageName);
        view.addObject("applyId", applyId);
        view.addObject("classId",classId);
        return view;
    }
    /**
     * 分页查询
     *
     * @param divideclassStudentVo 接受参数对象
     * @param page 当前页面
     * @param limit 页面数量
     * @return ReturnResult
     * @author caideyong
     * @date 2019-12-20 14:24:32
     */
    @BaseLog(module = "智能分班学生表,分班时导入的学生信息", classz = "智能分班学生", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/divideclass/divideclassstudent/page", method = RequestMethod.POST)
    public ReturnResult page(DivideclassStudentVo divideclassStudentVo, int page, int limit) {
        return divideclassStudentService.page(divideclassStudentVo, page, limit);
    }

    /**
     * 跳转添加或编辑界面
     *
     * @param id 主键
     * @return ReturnResult
     * @author caideyong
     * @date 2019-12-20 14:24:32
     */
    @BaseLog(module = "智能分班学生表,分班时导入的学生信息", classz = "智能分班学生", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/divideclass/divideclassstudent/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(String id) {
        ModelAndView view = new ModelAndView("/divideclass/divideclassstudent/divideclassStudentEdit");
        if (StringUtils.isNotBlank(id)) {
            view.addObject(divideclassStudentService.selectByPrimaryKey(id));
        }
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request 请求对象
     * @param divideclassStudentVo 接受参数对象
     * @return ReturnResult
     * @author caideyong
     * @date 2019-12-20 14:24:32
     */
    @BaseLog(module = "智能分班学生表,分班时导入的学生信息", classz = "智能分班学生", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/divideclass/divideclassstudent/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, DivideclassStudentVo divideclassStudentVo) {
        return divideclassStudentService.addOrUpdate(divideclassStudentVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request 请求对象
     * @param divideclassStudentVo 接受参数对象
     * @return ReturnResult
     * @author caideyong
     * @date 2019-12-20 14:24:32
     */
    @BaseLog(module = "智能分班学生表,分班时导入的学生信息", classz = "智能分班学生", methods = "逻辑删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/divideclass/divideclassstudent/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, DivideclassStudentVo divideclassStudentVo) {
        return divideclassStudentService.remove(divideclassStudentVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件物理删除
     *
     * @param request 请求对象
     * @param divideclassStudentVo 接受参数对象
     * @return ReturnResult
     * @author caideyong
     * @date 2019-12-20 14:24:32
     */
    @BaseLog(module = "智能分班学生表,分班时导入的学生信息", classz = "智能分班学生", methods = "物理对象对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/divideclass/divideclassstudent/delete", method = RequestMethod.GET)
    public ReturnResult delete(HttpServletRequest request, DivideclassStudentVo divideclassStudentVo) {
        return divideclassStudentService.delete(divideclassStudentVo, acceptCurrentUser(request));
    }

    /**
     * 批量导入学生信息
     * @author caideyong
     * @date 2019/12/20
     * @return ReturnResult
     */
    @BaseLog(module = "智能分班", classz = "智能分班学生", methods = "批量导入智能分班学生信息", businessType = BusinessType.IMPORT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/divideclass/divideclassstudent/importData", method = RequestMethod.POST)
    public ReturnResult importData(HttpServletRequest request, MultipartFile file, String catalog, String update, String applyId, String divideId) {
        return divideclassStudentService.importData(request, file, catalog, update, applyId, acceptCurrentUser(request),divideId);
    }

    /**
     * 数据导出
     *
     * @param divideclassStudentVo 传入参数对象
     * @param response         响应对象
     * @return void
     * @author caideyong
     * @date 2019/11/27
     */
    @RequestMapping(value = "/work/divideclass/divideclassstudent/export")
    public void export(HttpServletResponse response, DivideclassStudentVo divideclassStudentVo) throws IOException {
        divideclassStudentService.export(response, divideclassStudentVo);
    }
}